package com.team01.pokemon.service.impl;

import com.team01.pokemon.entity.Moves;
import com.team01.pokemon.mapper.MovesMapper;
import com.team01.pokemon.service.MovesService;
import com.team01.pokemon.vo.MovesDetailVO;
import com.team01.pokemon.vo.MovesQueryVO;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 * 招式表 服务实现类
 * </p>
 *
 * @author author
 * @since 2025-09-13
 */
@Transactional
@Service
public class MovesServiceImpl extends ServiceImpl<MovesMapper, Moves> implements MovesService {

    @Autowired
    private MovesMapper movesMapper;

    @Override
    public List<MovesDetailVO> queryMoves(MovesQueryVO queryVO) {
        // 根据查询条件选择合适的查询方法
        if (StringUtils.hasLength(queryVO.getPokemonName())) {
            return getMovesByPokemonName(queryVO.getPokemonName(), queryVO.getLearnMethod(),
                    queryVO.getMinLevel(), queryVO.getMaxLevel());
        } else if (StringUtils.hasLength(queryVO.getTypeName())) {
            return getMovesByTypeName(queryVO.getTypeName());
        } else if (StringUtils.hasLength(queryVO.getMoveName())) {
            return getMovesByMoveName(queryVO.getMoveName());
        } else if (queryVO.getMinLevel() != null && queryVO.getMaxLevel() != null) {
            return getMovesByLevelRange(queryVO.getMinLevel(), queryVO.getMaxLevel(), queryVO.getLearnMethod());
        } else {
            return getAllMoves();
        }
    }

    @Override
    public List<MovesDetailVO> getAllMoves() {
        return movesMapper.getAllMoves();
    }

    @Override
    public List<MovesDetailVO> getMovesByPokemonName(String pokemonName, String learnMethod, Integer minLevel,
            Integer maxLevel) {
        return movesMapper.getMovesByPokemonName(pokemonName, learnMethod, minLevel, maxLevel);
    }

    @Override
    public List<MovesDetailVO> getMovesByPokemonId(Integer pokemonId, String learnMethod, Integer minLevel,
            Integer maxLevel) {
        return movesMapper.getMovesByPokemonId(pokemonId, learnMethod, minLevel, maxLevel);
    }

    @Override
    public List<MovesDetailVO> getMovesByTypeName(String typeName) {
        return movesMapper.getMovesByTypeName(typeName);
    }

    @Override
    public List<MovesDetailVO> getMovesByMoveName(String moveName) {
        return movesMapper.getMovesByMoveName(moveName);
    }

    @Override
    public List<MovesDetailVO> getMovesByLevelRange(Integer minLevel, Integer maxLevel, String learnMethod) {
        return movesMapper.getMovesByLevelRange(minLevel, maxLevel, learnMethod);
    }
}
